﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Common;
using System.Data;
using V5_BLL;

namespace V5_EShop.Controls
{
    //用户浏览过的产品 格式    产品ID|时间      1|2010-10-10,
    public partial class getUserBrowseProductList : BasicControl
    {
        string paramValue = "";

        public string ParamValue
        {
            get { return paramValue; }
            set { paramValue = value; }
        }

        const string cUserBrowseProductList = "UserBrowseProductList";
        int pid = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                pid = Input.SetInt(Request["pid"]);
                //添加cookies
                Bind_ProductCookies();
                //绑定cookies
                Bind_rpList();
            }
        }
        //绑定产品cookies
        private void Bind_ProductCookies()
        {
            if (Request.Cookies[cUserBrowseProductList] != null)
            {
                string browseStr = Input.SetString(Request.Cookies[cUserBrowseProductList].Value);
                browseStr += "," + pid;
                this.Context.Response.Cookies.Add(new HttpCookie(cUserBrowseProductList, browseStr));
            }
            else
            {
                this.Context.Response.Cookies.Add(new HttpCookie(cUserBrowseProductList, pid.ToString()));
            }
        }
        //绑定浏览产品
        private void Bind_rpList()
        {
            Repeater rp = (Repeater)this.FindControl("rpList");
            if (rp != null)
            {
                if (Request.Cookies[cUserBrowseProductList] != null)
                {
                    string browseStr = Input.SetString(Request.Cookies[cUserBrowseProductList].Value);
                    string[] strArray = browseStr.Split(new char[] { ',' });

                    int row = 0;
                    string where = "";
                    string strWhere = " ID>0 ";

                    if (ParamValue != "")
                    {
                        row = Input.SetInt(Input.TagVal(ParamValue, "row"));
                        if (row < 1)
                        {
                            row = 10;
                        }
                        where = Input.SetString(Input.TagVal(ParamValue, "where"));
                        if (where.Trim() != "")
                        {
                            strWhere += " and " + where;
                        }
                    }
                    DataTable dt = new BLLProduct().GetList(row," ID in(" + browseStr + ") "," ID Desc").Tables[0];
                    rp.DataSource = dt;
                    rp.DataBind();
                }
            }
        }
    }
}